﻿@using System.Collections
@using ExampleWebApplication.Controllers
@using ExampleWebApplication.Models
@using ExampleWebApplication.Properties
<h2>
    @EntityFrameworkStrings.Example5
</h2>
<h3>
    <a target="_blank" href="http://demos.telerik.com/aspnet-mvc/razor/grid/aggregatesserverside">
        Telerik demo version</a>
</h3>
@(Html.Telerik().Grid<ProductModel>()
        .Name("Grid")
        .BindTo((IEnumerable)ViewBag.Data)
        .Columns(columns =>
        {
            columns.Bound(o => o.ProductName)
                    .Aggregate(aggregates => aggregates.Count())
                    .FooterTemplate(@<text>Total Count: @item.Count</text>)
                    .GroupFooterTemplate(@<text>Count: @item.Count</text>);

            columns.Bound(o => o.UnitPrice)
                    .Width(200)
                    .Aggregate(aggreages => aggreages.Sum())
                    .Format("{0:c}")
                    .FooterTemplate(@<text>Total Sum: @item.Sum.Format("{0:c}")</text>)
                    .GroupFooterTemplate(@<text>Sum: @item.Sum.Format("{0:c}")</text>);

            columns.Bound(o => o.Units_OnOrder)
                    .Width(200)
                    .Aggregate(aggregates => aggregates.Average())
                    .FooterTemplate(@<text>Average: @item.Average</text>)
                    .GroupFooterTemplate(@<text>Average: @item.Average</text>);

            columns.Bound(o => o.UnitsInStock)
                    .Width(100)
                    .Aggregate(aggregates => aggregates.Count().Min().Max())
                    .FooterTemplate(
                    @<text>
<div>
    Min: @item.Min</div>
<div>
    Max: @item.Max</div>
</text>)
                    .GroupHeaderTemplate(@<text>@item.Title: @item.Key (Count: @item.Count)</text>);
        })
        .DataBinding(dataBinding => dataBinding.Server().Select<EntityFrameworkController>(ctr => ctr.AggregatesServerSide(null)))
        .Pageable(settings => settings.Total((int)ViewBag.Total).PageSize(10)/* We have to inform the pageSize in the control too.*/)
        .Sortable().Filterable().EnableCustomBinding(true)
        .Groupable(settings => settings.Groups(groups => groups.Add(o => o.UnitsInStock)).Visible(false))
)